/// qt 一些特殊object实例
#include <QTime>
#include <QApplication>
#include <QEventLoop>

#include <QDebug>

class TimeUtil {
public:
    static void demoQTime() {
        QTime curTime = curTime.currentTime();
        qDebug() << "curTime:" << curTime << "," << curTime.msecsSinceStartOfDay();

        QTime t1 = curTime.addSecs(100);
        qDebug() << "t1:" << t1 << "," << t1.msecsSinceStartOfDay() << ", " << curTime.msecsTo(t1);

        QTime t2(23, 59, 59);
        QTime t3 = t2.addMSecs(1100);
        qDebug() << "t2:" << t2 << ", " << t2.msecsSinceStartOfDay();
        qDebug() << "t3:" << t3 << ", " << t3.msecsSinceStartOfDay() << ", " << t3.secsTo(t2);

        int count = 0;
        while (true) {
            TimeUtil::msleep(3000);
            qDebug() << "sleep " << count++ << ", " << QTime::currentTime();
        }
    }

    static void msleep(long msec) {
        QTime markT;
        markT.start();
        while (markT.elapsed() < msec) {
            QCoreApplication::processEvents(QEventLoop::AllEvents, msec);
        }
    }
};

int main(int argc, char *argv[])
{
    int op = 1;
    switch (op) {
    case 1:
        TimeUtil::demoQTime();
        break;
    }

    return 0;
}
